Repository navigation
feat(companion,ui): desktop mobile companion server, settings UI, and dev helper (#118) - #147
Merged
Merged
Conversation
…gs UI, and dev helper (#118) Implement desktop-side TRACE mobile companion service per docs/design/mobile.md and docs/ui.md §3.12: - internal/companion: LAN/VPN interface & source filter, TLS 1.3 self-signed ECDSA P-256 cert/fingerprint/64-bit identity code, one-time QR + short-code pairing with desktop confirmation & QR rescan address update, companion.json v1 (0600, GuardDataSchemas, SHA-256 token hashes, max 5 devices, per-device homePositions), rate limiting, read-only & control HTTP APIs, bounded WebSocket event hub with bye{reason}, MediaPath-whitelisted Range streaming with extension-accurate Content-Type and 480/2560 px JPEG thumbnails. - internal/settings, internal/service, internal/shell, internal/ui: companion:{enabled,port} settings field, Settings › 移动端 UI + pairing/confirmation dialog, shared feed/seen baseline sync, shutdown bye on exit/update/disable. - tools/companiondev: local synthetic dev server helper (-listen 127.0.0.1 -advertise 10.0.2.2 -auto-approve -prepair). - tools/uishots (4 new mobile settings scenes, 357/357 pass), tools/check (INV-05 & trace-server exclusion), and docs updates. Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
Owner
Author
|
Agent:审查结论:先修复(审查提交 整体架构、协议边界、TLS 1.3 指纹固定、LAN/VPN 来源过滤、物理网卡 CGNAT 排除、 阻塞问题1. [P0]
|
Fix all 7 review blockers and 3 polish items from PR #147: 1. handlePutFeedPosition: map ErrInvalidPositionSite->400, ErrDeviceNotFound->401, persistence errors->500 internal without exposing err.Error() or local paths. 2. pairingManager: add transient approving state in Approve to prevent concurrent duplicate devices/orphans (with rollback if cleared mid-persist), and preserve approved one-time token in Poll when ctx.Done() fires. 3. MaxDevices (5): allow StartPairing & UI '添加手机' at 5/5 for FR-MOB-007 paired-device QR rescan address updates (with UI hint) while 6th new device still gets 409 device_limit. 4. subs:check & POST /api/v1/checks: route progress:* messages to EventSubsCheck with sanitized Message; validate subIds (404) and unauthenticated-only site targets (412 auth_required with site); emit sanitized subs:check error events for async check failures. 5. handleMedia / handleAvatar: enforce requireAnyLogin at entry. 6. reconcileInterfaces: close newly opened listeners if Manager stopped concurrently. 7. tools/companiondev: write avatars using service.AccountAvatarPath hash filenames (<site>-<sha256[:10]>.png) and assert in TestSeedSyntheticData. Polish: deduplicate live recordings/incidents, net.JoinHostPort for IPv6 pairing address, expanded Windows firewall guidance per mobile.md §9.2. Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
Owner
Author
|
Agent:复审结论:可合并(复审提交 上轮阻塞项复核(7/7 已修复并带回归测试)
上轮 3 条非阻塞建议( 复审范围与验证证据
|
5 of 6 tasks
Owner
Author
|
Agent:仓库所有者已在 2026-11-27 当前会话明确授权合并本高风险 PR( |
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对应 issue
Closes #118(电脑端移动端服务、设置页界面与本地联调辅助工具;手机端应用与实机验收在其他 issue 中推进)
改了什么
实现 TRACE 移动端的电脑端服务端、设置页界面、开发联调辅助工具、质量门禁规则与文档同步(遵循
docs/design/mobile.md§3–§6、§8、§12 与docs/ui.md§3.12):internal/companion/(纯 Go,零 MyGo 依赖,符合 INV-05):100.64.0.0/10上监听和接受请求,明确排除物理网卡 CGNAT 与公网地址(Windows 经GetAdaptersAddresses识别IF_TYPE_TUNNEL/IF_TYPE_PROP_VIRTUAL/IF_TYPE_PPP);端口被占用时保持关闭并报错,不悄悄换端口;定时感知网卡变化重新绑定。<DataDir>/companion/tls/{cert.pem,key.pem}(私钥0600)生成并加载 ECDSA P-256 自签名证书,计算 SHA-256 指纹与 64 位可读身份码(XXXX-XXXX-XXXX-XXXX),支持“重置移动端身份”重新生成证书并立即撤销全部设备。trace-pair:<base64url>,128 位随机码)+ 8 位去混淆手动短码(累计错误 5 次自动作废),pairId+X-Trace-Pair-Secret(仅存 SHA-256、2 分钟有效),桌面端确认后才发放 32 字节设备令牌(单次取回),companion.jsonv1(0600原子写、接入storage.GuardDataSchemas高版本拒绝与损坏备份恢复、最多 5 台、仅存tokenHash与常数时间比对);已配对设备携带有效 Bearer 令牌复扫同节点二维码可免确认更新地址。Cache-Control: no-store与协议/版本/通道头校验;按来源 IP 限流(1 分钟 5 次失败封 10 分钟,返回429 rate_limited);映射全部只读接口(/api/v1/status、/feed、/feed/seen、/feed/position、/library、/library/{key}、/subscriptions、/subscriptions/accounts、/checks/plan、/tasks/downloads、/tasks/downloads/{id}、/tasks/queues、/live/recordings、/live/incidents、/conflicts、/transfers)与有限控制接口(下载任务与缓存队列操作、直播开始/停止且显式拒绝微博与 X、检查更新与取消、手机端解除配对);纯标准库 RFC 6455 WebSocket(GET /api/v1/events)为每条连接维护 256 条有界队列、1 秒进度合并、满队丢弃最旧进度并下发resync(INV-13),退出/更新/关开关/移除设备时 1 秒内下发bye{reason}后断开。/api/v1/media/{key}/{relPath...}与/api/v1/avatars/{site}/{uid}统一要求至少一个站点已登录(否则412 auth_required),媒体严格经LibraryService.MediaPath白名单读取登记文件,按扩展名返回准确Content-Type(含video/mp4、audio/mp4、audio/flac等),原生支持Range/If-Range;支持?w=480(写入<DataDir>/cache/companion-thumbs/,256 MiB LRU 并在条目单删/批量删时联动失效)与?w=2560按需 JPEG 缩放;头像离线提供本机 PNG。POST /api/v1/feed/seen更新共享ui-state.json.homeSeen并通过EventHub同步清除桌面端未读圆点;GET/PUT /api/v1/feed/position按设备存在companion.json,与桌面端ui-state.json.homePositions完全隔离。internal/settings、internal/service、internal/shell、internal/ui):settings.json新增可选companion: {enabled, port}(保持结构版本 1,默认关)。service.NewBackend将companion.jsonv1 加入GuardDataSchemas,并提供PublishFeedSeen。internal/shell在启动时初始化/按设置自启companion.Manager、绑定到 UI,并在退出或--quit-for-update时下发bye{exit|update}后优雅关闭。internal/ui新增“设置 › 移动端”分类(位于“远程”之后)、监听状态与防火墙提示、端口配置、已配对手机列表(在线状态/改名/内联移除确认)、顶层配对二维码与桌面确认对话框及重置身份内联确认。tools/companiondev、tools/uishots、tools/check、文档):go run ./tools/companiondev(在临时数据目录填充合成视频/微博双图/直播录像与本机头像,支持-listen 127.0.0.1 -advertise 10.0.2.2 -port 47382 -auto-approve -prepair便于 Android 模拟器联调)。tools/uishots新增 4 个移动端设置场景(settings-mobile-off、settings-mobile-active、settings-mobile-pair-qr、settings-mobile-pair-confirm)。tools/check增加cmd/trace-server禁止依赖internal/companion规则及internal/companionINV-05 测试用例。docs/design/data-and-cache.md、docs/design/architecture.md、docs/dev-rules/engineering.md、docs/requirements.md§2.13 状态。风险评估
risk:high标签,等用户合并):引入新的持久化数据文件<DataDir>/companion.json(v1,含GuardDataSchemas注册)、新的settings.json字段companion,以及新的本地 HTTPS/WebSocket 网络监听面。按docs/dev-rules/workflow.md#high-risk不由 Agent 合并。验证
所有命令在工作区根目录以
TRACE_QUIET=1运行,零真实站点请求:go test -count=20 ./internal/companion0(3.902s),全部 9 组测试 20/20 通过(含网卡与来源过滤、companion.json损坏恢复与高版本拒绝、令牌哈希与 5 台上限、配对安全规则、MITM 身份码不符中止、256 队列满非阻塞与resync、固定证书 TLS 1.3 回环集成端到端配对/Range 206/480px 缩略图/未登记文件拒绝/微博开录拒绝/未登录站点auth_required/复扫免确认/WebSocketbye{exit}/哨兵零泄漏)。go test -v -run "TestMobile" ./internal/ui && go test -v ./tools/companiondev ./internal/shell ./tools/check0,TestMobileSettingsTogglePortPairingAndDevices、TestMobileFeedSeenEventSyncsDesktopHomeBaseline、TestSeedSyntheticData、internal/shell全部 26 项与tools/check全部通过。go run ./tools/uishots -out artifacts/uishots0,generated 357 screenshots ... (all passed)(含 4 个新增settings-mobile-*场景,无横向溢出)。go run ./tools/check(gofmt -l、go vet ./...、go test ./...、依赖方向、trace-serverLinux amd64/arm64 交叉构建、tools/checkdocs加载 14 条本地参考词、git diff --check HEAD)0(ALL CHECKS PASSED in 6m19.439s)。LESSONS.md工作树pre-pushhook 已知问题使用git push --no-verify(已在推送前完整通过go run ./tools/check)。not-run)与已知局限:go test -race:not-run(本机无 cgo 工具链)。not-run(待手机端应用完成及真机验收)。关联文档与不变量检查
internal/companion零 MyGo 依赖(INV-05),cmd/trace-server不链接internal/companionLibraryService.MediaPath白名单强制执行(INV-08),错误响应与日志不泄漏 Cookie、设备令牌、配对码与本机绝对路径(NFR-MOB-SEC-003)companion.jsonv1 接入storage.GuardDataSchemas,权限0600,原子写与损坏备份恢复tools/checkdocs公开内容检查通过(无绝对路径、凭证或参考项目名)